import os
from PIL import Image, ImageDraw, ImageFont

def create_empty_cart_image(output_path):
    """Create an empty cart image."""
    width, height = 300, 200
    img = Image.new('RGBA', (width, height), (0, 0, 0, 0))
    draw = ImageDraw.Draw(img)
    
    # Draw cart outline
    cart_width, cart_height = 80, 60
    x1 = (width - cart_width) // 2
    y1 = (height - cart_height) // 2 - 20
    
    # Cart body
    draw.rectangle((x1, y1 + 20, x1 + cart_width, y1 + cart_height), outline=(200, 200, 200), width=3)
    
    # Cart handle
    draw.arc((x1 - 15, y1, x1 + 15, y1 + 30), 0, 180, fill=(200, 200, 200), width=3)
    
    # Cart wheels
    wheel_radius = 8
    draw.ellipse((x1 + 15 - wheel_radius, y1 + cart_height, x1 + 15 + wheel_radius, y1 + cart_height + wheel_radius * 2), outline=(200, 200, 200), width=3)
    draw.ellipse((x1 + cart_width - 15 - wheel_radius, y1 + cart_height, x1 + cart_width - 15 + wheel_radius, y1 + cart_height + wheel_radius * 2), outline=(200, 200, 200), width=3)
    
    # Draw text
    try:
        font = ImageFont.truetype("arial.ttf", 16)
    except IOError:
        font = ImageFont.load_default()
        
    text = "购物车空空如也"
    text_width = draw.textlength(text, font=font)
    draw.text(((width - text_width) // 2, y1 + cart_height + 40), text, fill=(150, 150, 150), font=font)
    
    img.save(output_path)
    print(f"创建空购物车图片: {output_path}")

if __name__ == "__main__":
    # Create output directory if it doesn't exist
    output_dir = "../frontend/images"
    os.makedirs(output_dir, exist_ok=True)
    
    # Create empty cart image
    create_empty_cart_image(os.path.join(output_dir, "empty-cart.png"))
    
    print("空购物车图片创建完成！")